
#include "stdafx.h"

#include "../../loader.h"
using namespace dlguif;

#include <iostream>
using std::cout;
using std::cerr;
using std::endl;




void CALLBACK OnGuiEvent(void* user_context, const callback_info* ci)
{
	static int count = 0;
	count ++;

	Loader* ploader = (Loader*)user_context;

	cout << "GUI event! " << count << endl;
	cout << "tag: " << ci->tag << endl;
	cout << "type: " << Loader::event_type_to_string(ci->eventType) << endl;
	cout << "Param1: " << ci->param1 <<  endl;
	cout << "Param2: " << ci->param2 <<  endl;
	cout << "Class name: " << ci->class_name << endl;
	cout << "Name: " << ci->name << endl;
	cout << "--------------------------" << endl;

	if(ci->tag == 1000)
	{
		ploader->Terminate();
	}

}


int _tmain(int argc, _TCHAR* argv[])
{
	Loader loader; //(L"j:/dlguif/dlguif/delphi_dll_project/dlguif.dll");
	loader.SetGuiEventCallBack(OnGuiEvent, (void*)&loader );
	void* form = loader.CreateForm("caption", "myform", 10, 10, 800, 600);
	void* mm = loader.CreateMainMenu(form);
	loader.CreateMainMenuItem(mm, NULL, "&File");
	loader.CreateMainMenuItem(mm, NULL, "&Help");


	loader.CreateMainMenuItem(mm, "&File", "Open");
	loader.CreateMainMenuItem(mm, "&File", "Close");
	loader.CreateMainMenuItem(mm, "&File", "-");
	void* mmi_Exit = loader.CreateMainMenuItem(mm, "&File", "Exit");
	loader.SetComponentTag(mmi_Exit, 1000);



	loader.CreateMainMenuItem(mm, "&Help", "Contents");
	loader.CreateMainMenuItem(mm, "&Help", "-");
	loader.CreateMainMenuItem(mm, "&Help", "About");






	loader.ShowForm(form);

	//loader.Run();

	//while( loader.GetControlVisible(form) )
	//{
	//	loader.ProcessMessages();
	//	Sleep(1);
	//}


	while( loader.ProcessMessages() )
	{
		Sleep(1);
	}





	return 0;
}